<?php
/*
 * Copyright 2007 Bjørn Tore Håvie
 * 
 * This file is part of ITSBOT.
 * 
 * ITSBOT is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ITSBOT is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ITSBOT.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * @package ITSBOT
 * @subpackage Main
 * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License
 */
/**
 * Command arguments
 *
 */
class Args{
	public $msg;
	public $sender;
	public $origin;
	public $target;
	
	private $parts;
	private $i = 0;
	
	public function __construct($msg, $sender, $origin, $target){
		$this->msg = $msg;
		$this->sender = $sender;
		$this->origin = $origin;
		$this->target = $target;
		$this->parts = explode(' ', $msg);
	}
	
	/**
	 * Read a word
	 *
	 * @return string
	 */
	public function ReadWord(){
		return $this->parts[$this->i++];
	}
	
	/**
	 * Read the rest of the message
	 *
	 * @return string
	 */
	public function ReadRest(){
		$out = array();
		for($n = 0; $part = $this->parts[$n]; $n++){
			if($n >= $this->i)
				$out[] = $part;
		}
		return implode(' ', $out);
	}
	
	/**
	 * Read a channel name, auto-prepends # if necesarry
	 *
	 * @return string
	 */
	public function ReadChannel(){
		return (substr($this->parts[$this->i], 1, 1) == '#')? $this->parts[$this->i++] : '#' . $this->parts[$this->i++];
	}
}
?>